package com.demo.service.base.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.dto.ComboBoxDto;
import com.demo.mapper.base.ColumnBaseInfoMapper;
import com.demo.model.base.ColumnBaseInfo;
import com.demo.model.base.ColumnBaseInfoExample;
import com.demo.service.base.ColumnBaseInfoService;

@Service
public class ColumnBaseInfoServiceImpl implements ColumnBaseInfoService {
	@Autowired
	ColumnBaseInfoMapper mapper;
	
	@Override
	@Transactional
	public int add(ColumnBaseInfo record) {
		if (null == record) {
			return 0;
		}
		return mapper.insert(record);
	}

	@Override
	@Transactional
	public int addBatch(List<ColumnBaseInfo> records) {
		if (null == records || records.size() == 0) {
			return 0;
		}
		return mapper.insertBatch(records);
	}

	@Override
	@Transactional
	public int deleteByCondition(ColumnBaseInfoExample example) {
		return mapper.deleteByExample(example);
	}

	@Override
	public ColumnBaseInfo getById(Integer id) {
		return mapper.selectByPrimaryKey(id);
	}

	@Override
	public List<ColumnBaseInfo> findByCondition(ColumnBaseInfoExample example) {
		return mapper.selectByExample(example);
	}

	@Override
	public int getCount(ColumnBaseInfoExample example) {
		return mapper.countByExample(example);
	}

	@Override
	@Transactional
	public int deleteAndAddBatch(String tableName, List<ColumnBaseInfo> records) {
		ColumnBaseInfoExample example = new ColumnBaseInfoExample();
		example.or().andTableNameEqualTo(tableName);
		deleteByCondition(example);
		return addBatch(records);
	}

	@Override
	public List<ComboBoxDto> getComboOfTableName() {
		return mapper.getComboOfTableName();
	}

}
